// Copyright 2022 jeff.li. and/or its affiliates.
#include <tbir/runtime/threadpool/i_thread_pool.h>
#include <exception>

namespace tbir::runtime::internal {

    void IThreadPool::WaitBulk(std::vector<IRunnablePtr> &runners) {
        std::exception_ptr eptr;
        for (auto &runner : runners) {
            try {
                runner->Wait();
            } catch (...) {
                if (!eptr) {
                    eptr = std::current_exception();
                }
            }
        }
        if (eptr) {
            std::rethrow_exception(eptr);
        }
    }

}  // namespace tbir::runtime::internal